package net.muchine.core.misc;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import net.muchine.core.support.Codes;

public class PropertyConverter {
	@SuppressWarnings("unused")
	private void createTimeZoneResourceBundle() {
		File source = new File("D:\\timezone.txt");
		File target = new File("D:\\target.txt");
		
		BufferedReader br = null;
		BufferedWriter bw = null;
		
		try {
			br = new BufferedReader(new FileReader(source));
			bw = new BufferedWriter(new FileWriter(target));
			String line = null;
					
			while ((line = br.readLine()) != null) {
				int firstQuotation = line.indexOf("\"");
				int secondQuotation = line.indexOf("\"", firstQuotation + 1);
				
				System.out.println(firstQuotation + ", " + secondQuotation);
				String timezone = line.substring(firstQuotation + 1, secondQuotation);
				System.out.println("timezone: " + timezone);
				
				int firstDash = line.indexOf(">");
				int secondDash = line.indexOf("<", firstDash + 1);
				
				String value = line.substring(firstDash + 1, secondDash);
				
				bw.write(timezone.replace(" ", "\\u0020") + " = " + value.replace(" ", "\\u0020") + "\r\n");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			try {
				if (br != null) br.close();
				if (bw != null) bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	@SuppressWarnings("unused")
	private void createLanguageResourceBundle() {
		File source = new File("D:\\language.txt");
		File target = new File("D:\\target.txt");
		
		BufferedReader br = null;
		BufferedWriter bw = null;
		
		try {
			br = new BufferedReader(new FileReader(source));
			bw = new BufferedWriter(new FileWriter(target));
			String line = null;
					
			while ((line = br.readLine()) != null) {
				int firstQuotation = line.indexOf("\"");
				int secondQuotation = line.indexOf("\"", firstQuotation + 1);
				
				System.out.println(firstQuotation + ", " + secondQuotation);
				String language = line.substring(firstQuotation + 1, secondQuotation);
				System.out.println("language: " + language);
				
				int firstDash = line.indexOf(">");
				int secondDash = line.indexOf("<", firstDash + 1);
				
				String value = line.substring(firstDash + 1, secondDash);
				
				bw.write(language.replace(" ", "\\u0020") + " = " + value.replace(" ", "\\u0020") + "\r\n");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			try {
				if (br != null) br.close();
				if (bw != null) bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		PropertyConverter converter = new PropertyConverter();
	
		converter.createLanguageResourceBundle();
//		codes.createTimeZoneResourceBundle();
//		codes.getTimeZoneList();
	}
}
